import request, { type ListQuery } from "@/utils/request";

const BRANK_BASE_URL = "/api";

export interface Brand {
  id: number;
  name: string;
  image_url: string;
}

export interface BrandQueryForm extends ListQuery {}

export interface BrandFormData {
  id?: number;
  name: string;
  image_url: string;
}

export const BrandAPI = {
  /**
   * 获取品牌分页列表
   * @param queryParams 查询参数
   */
  getPage(queryParams?: BrandQueryForm) {
    return request<any, Brand[]>({
      url: `${BRANK_BASE_URL}/brands/`,
      method: "get",
      params: queryParams,
    });
  },

  /**
   * 创建品牌
   * @param data 品牌数据
   */
  create(data: BrandFormData) {
    return request<any, Brand>({
      url: `${BRANK_BASE_URL}/brands/`,
      method: "post",
      data,
    });
  },

  /**
   * 更新品牌
   * @param id 品牌ID
   * @param data 品牌数据
   */
  update(id: number, data: BrandFormData) {
    return request<any, Brand>({
      url: `${BRANK_BASE_URL}/brands/${id}/`,
      method: "put",
      data,
    });
  },

  /**
   * 删除品牌
   * @param id 品牌ID
   */
  delete(id: number) {
    return request<any, undefined>({
      url: `${BRANK_BASE_URL}/brands/${id}/`,
      method: "delete",
    });
  },

  /**
   * 获取品牌详情
   * @param id 品牌ID
   */
  getDetail(id: number) {
    return request<any, Brand>({
      url: `${BRANK_BASE_URL}/brands/${id}/`,
      method: "get",
    });
  },
};

export default BrandAPI;
